(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

p(0) → 0
p(s(X)) → X
leq(0, Y) → true
leq(s(X), 0) → false
leq(s(X), s(Y)) → leq(X, Y)
if(true, X, Y) → activate(X)
if(false, X, Y) → activate(Y)
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y)))
0n__0
s(X) → n__s(X)
diff(X1, X2) → n__diff(X1, X2)
p(X) → n__p(X)
activate(n__0) → 0
activate(n__s(X)) → s(activate(X))
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2))
activate(n__p(X)) → p(activate(X))
activate(X) → X

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

p(0) → 0 [1]
p(s(X)) → X [1]
leq(0, Y) → true [1]
leq(s(X), 0) → false [1]
leq(s(X), s(Y)) → leq(X, Y) [1]
if(true, X, Y) → activate(X) [1]
if(false, X, Y) → activate(Y) [1]
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y))) [1]
0n__0 [1]
s(X) → n__s(X) [1]
diff(X1, X2) → n__diff(X1, X2) [1]
p(X) → n__p(X) [1]
activate(n__0) → 0 [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2)) [1]
activate(n__p(X)) → p(activate(X)) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

(3) CpxWeightedTrsRenamingProof (BOTH BOUNDS(ID, ID) transformation)

Renamed defined symbols to avoid conflicts with arithmetic symbols:

0 => 0'

(4) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

p(0') → 0' [1]
p(s(X)) → X [1]
leq(0', Y) → true [1]
leq(s(X), 0') → false [1]
leq(s(X), s(Y)) → leq(X, Y) [1]
if(true, X, Y) → activate(X) [1]
if(false, X, Y) → activate(Y) [1]
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y))) [1]
0'n__0 [1]
s(X) → n__s(X) [1]
diff(X1, X2) → n__diff(X1, X2) [1]
p(X) → n__p(X) [1]
activate(n__0) → 0' [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2)) [1]
activate(n__p(X)) → p(activate(X)) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

(5) InnermostUnusableRulesProof (BOTH BOUNDS(ID, ID) transformation)

Removed the following rules with non-basic left-hand side, as they cannot be used in innermost rewriting:

p(0') → 0' [1]
p(s(X)) → X [1]
leq(0', Y) → true [1]
leq(s(X), 0') → false [1]
leq(s(X), s(Y)) → leq(X, Y) [1]

Due to the following rules that have to be used instead:

0'n__0 [1]
s(X) → n__s(X) [1]

(6) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

if(true, X, Y) → activate(X) [1]
if(false, X, Y) → activate(Y) [1]
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y))) [1]
0'n__0 [1]
s(X) → n__s(X) [1]
diff(X1, X2) → n__diff(X1, X2) [1]
p(X) → n__p(X) [1]
activate(n__0) → 0' [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2)) [1]
activate(n__p(X)) → p(activate(X)) [1]
activate(X) → X [1]

Rewrite Strategy: INNERMOST

(7) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(8) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

if(true, X, Y) → activate(X) [1]
if(false, X, Y) → activate(Y) [1]
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y))) [1]
0'n__0 [1]
s(X) → n__s(X) [1]
diff(X1, X2) → n__diff(X1, X2) [1]
p(X) → n__p(X) [1]
activate(n__0) → 0' [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2)) [1]
activate(n__p(X)) → p(activate(X)) [1]
activate(X) → X [1]

The TRS has the following type information:
if :: true:false:leq → n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
true :: true:false:leq
activate :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
false :: true:false:leq
diff :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
leq :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s → true:false:leq
n__0 :: n__0:n__p:n__diff:n__s
n__s :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
n__diff :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
n__p :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
0' :: n__0:n__p:n__diff:n__s
s :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s
p :: n__0:n__p:n__diff:n__s → n__0:n__p:n__diff:n__s

Rewrite Strategy: INNERMOST

(9) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

if(v0, v1, v2) → null_if [0]

And the following fresh constants:

null_if

(10) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

if(true, X, Y) → activate(X) [1]
if(false, X, Y) → activate(Y) [1]
diff(X, Y) → if(leq(X, Y), n__0, n__s(n__diff(n__p(X), Y))) [1]
0'n__0 [1]
s(X) → n__s(X) [1]
diff(X1, X2) → n__diff(X1, X2) [1]
p(X) → n__p(X) [1]
activate(n__0) → 0' [1]
activate(n__s(X)) → s(activate(X)) [1]
activate(n__diff(X1, X2)) → diff(activate(X1), activate(X2)) [1]
activate(n__p(X)) → p(activate(X)) [1]
activate(X) → X [1]
if(v0, v1, v2) → null_if [0]

The TRS has the following type information:
if :: true:false:leq → n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
true :: true:false:leq
activate :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
false :: true:false:leq
diff :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
leq :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if → true:false:leq
n__0 :: n__0:n__p:n__diff:n__s:null_if
n__s :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
n__diff :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
n__p :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
0' :: n__0:n__p:n__diff:n__s:null_if
s :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
p :: n__0:n__p:n__diff:n__s:null_if → n__0:n__p:n__diff:n__s:null_if
null_if :: n__0:n__p:n__diff:n__s:null_if

Rewrite Strategy: INNERMOST

(11) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
false => 0
n__0 => 0
null_if => 0

(12) Obligation:

Complexity RNTS consisting of the following rules:

0' -{ 1 }→ 0 :|:
activate(z) -{ 1 }→ X :|: X >= 0, z = X
activate(z) -{ 1 }→ s(activate(X)) :|: z = 1 + X, X >= 0
activate(z) -{ 1 }→ p(activate(X)) :|: z = 1 + X, X >= 0
activate(z) -{ 1 }→ diff(activate(X1), activate(X2)) :|: X1 >= 0, X2 >= 0, z = 1 + X1 + X2
activate(z) -{ 1 }→ 0' :|: z = 0
diff(z, z') -{ 1 }→ if(1 + X + Y, 0, 1 + (1 + (1 + X) + Y)) :|: z' = Y, Y >= 0, X >= 0, z = X
diff(z, z') -{ 1 }→ 1 + X1 + X2 :|: X1 >= 0, X2 >= 0, z = X1, z' = X2
if(z, z', z'') -{ 1 }→ activate(X) :|: z' = X, Y >= 0, z = 1, z'' = Y, X >= 0
if(z, z', z'') -{ 1 }→ activate(Y) :|: z' = X, Y >= 0, z'' = Y, X >= 0, z = 0
if(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
p(z) -{ 1 }→ 1 + X :|: X >= 0, z = X
s(z) -{ 1 }→ 1 + X :|: X >= 0, z = X

Only complete derivations are relevant for the runtime complexity.

(13) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V2),0,[if(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[diff(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[fun(Out)],[]).
eq(start(V, V1, V2),0,[s(V, Out)],[V >= 0]).
eq(start(V, V1, V2),0,[p(V, Out)],[V >= 0]).
eq(start(V, V1, V2),0,[activate(V, Out)],[V >= 0]).
eq(if(V, V1, V2, Out),1,[activate(X3, Ret)],[Out = Ret,V1 = X3,Y1 >= 0,V = 1,V2 = Y1,X3 >= 0]).
eq(if(V, V1, V2, Out),1,[activate(Y2, Ret1)],[Out = Ret1,V1 = X4,Y2 >= 0,V2 = Y2,X4 >= 0,V = 0]).
eq(diff(V, V1, Out),1,[if(1 + X5 + Y3, 0, 1 + (1 + (1 + X5) + Y3), Ret2)],[Out = Ret2,V1 = Y3,Y3 >= 0,X5 >= 0,V = X5]).
eq(fun(Out),1,[],[Out = 0]).
eq(s(V, Out),1,[],[Out = 1 + X6,X6 >= 0,V = X6]).
eq(diff(V, V1, Out),1,[],[Out = 1 + X11 + X21,X11 >= 0,X21 >= 0,V = X11,V1 = X21]).
eq(p(V, Out),1,[],[Out = 1 + X7,X7 >= 0,V = X7]).
eq(activate(V, Out),1,[fun(Ret3)],[Out = Ret3,V = 0]).
eq(activate(V, Out),1,[activate(X8, Ret0),s(Ret0, Ret4)],[Out = Ret4,V = 1 + X8,X8 >= 0]).
eq(activate(V, Out),1,[activate(X12, Ret01),activate(X22, Ret11),diff(Ret01, Ret11, Ret5)],[Out = Ret5,X12 >= 0,X22 >= 0,V = 1 + X12 + X22]).
eq(activate(V, Out),1,[activate(X9, Ret02),p(Ret02, Ret6)],[Out = Ret6,V = 1 + X9,X9 >= 0]).
eq(activate(V, Out),1,[],[Out = X10,X10 >= 0,V = X10]).
eq(if(V, V1, V2, Out),0,[],[Out = 0,V3 >= 0,V2 = V4,V5 >= 0,V = V3,V1 = V5,V4 >= 0]).
input_output_vars(if(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(diff(V,V1,Out),[V,V1],[Out]).
input_output_vars(fun(Out),[],[Out]).
input_output_vars(s(V,Out),[V],[Out]).
input_output_vars(p(V,Out),[V],[Out]).
input_output_vars(activate(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [fun/1]
1. non_recursive : [p/2]
2. non_recursive : [s/2]
3. recursive [non_tail,multiple] : [activate/2,diff/3,if/4]
4. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is completely evaluated into other SCCs
1. SCC is completely evaluated into other SCCs
2. SCC is completely evaluated into other SCCs
3. SCC is partially evaluated into activate/2
4. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations activate/2
* CE 11 is refined into CE [14]
* CE 13 is refined into CE [15]
* CE 12 is refined into CE [16]
* CE 10 is refined into CE [17]
* CE 8 is refined into CE [18]
* CE 9 is refined into CE [19]


### Cost equations --> "Loop" of activate/2
* CEs [19] --> Loop 7
* CEs [17] --> Loop 8
* CEs [18] --> Loop 9
* CEs [16] --> Loop 10
* CEs [14,15] --> Loop 11

### Ranking functions of CR activate(V,Out)
* RF of phase [7,8,9,10]: [V]

#### Partial ranking functions of CR activate(V,Out)
* Partial RF of phase [7,8,9,10]:
- RF of loop [7:1,7:2,7:3,8:1,8:2,9:1,9:2,10:1]:
V


### Specialization of cost equations start/3
* CE 2 is refined into CE [20]
* CE 3 is refined into CE [21]
* CE 4 is refined into CE [22,23]
* CE 5 is refined into CE [24]
* CE 6 is refined into CE [25,26]
* CE 7 is refined into CE [27,28]


### Cost equations --> "Loop" of start/3
* CEs [20,21,22,23,24,25,26,27,28] --> Loop 12

### Ranking functions of CR start(V,V1,V2)

#### Partial ranking functions of CR start(V,V1,V2)


Computing Bounds
=====================================

#### Cost of chains of activate(V,Out):
* Chain [11]: 2
with precondition: [V=Out,V>=0]

* Chain [multiple([7,8,9,10],[[11]])]: 9*it(7)+2*it([11])+0
Such that:it([11]) =< 2*V+1
aux(1) =< V
it(7) =< aux(1)

with precondition: [V>=1,Out>=0,V>=Out]


#### Cost of chains of start(V,V1,V2):
* Chain [12]: 2*s(1)+9*s(3)+2*s(4)+9*s(6)+2*s(7)+9*s(9)+4
Such that:s(8) =< V
s(7) =< 2*V+1
s(5) =< V1
s(4) =< 2*V1+1
s(2) =< V2
s(1) =< 2*V2+1
s(9) =< s(8)
s(6) =< s(5)
s(3) =< s(2)

with precondition: []


Closed-form bounds of start(V,V1,V2):
-------------------------------------
* Chain [12] with precondition: []
- Upper bound: nat(V)*9+4+nat(V1)*9+nat(V2)*9+nat(2*V+1)*2+nat(2*V1+1)*2+nat(2*V2+1)*2
- Complexity: n

### Maximum cost of start(V,V1,V2): nat(V)*9+4+nat(V1)*9+nat(V2)*9+nat(2*V+1)*2+nat(2*V1+1)*2+nat(2*V2+1)*2
Asymptotic class: n
* Total analysis performed in 195 ms.

(14) BOUNDS(1, n^1)